﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
using Lib = OpenGLDiagLibrary;

namespace OpenGLDiag
{
    public partial class MainForm : Form
    {
        private Lib.Probing _probing = null;

        public MainForm()
        {
            InitializeComponent();

            _probing = new Lib.Probing();
            this.Load += MainForm_Load;
        }

        /// <summary>
        /// Retrieves information about the system
        /// </summary>
        void MainForm_Load(object sender, EventArgs e)
        {
            string sOS = _probing.GetInstalledOS();
            if (string.IsNullOrWhiteSpace(sOS))
                sOS = "Undetected";
            lblOS.Text += "  " + sOS;

            lblGPU.Text += "  " + GetGraphicsCardName();

            string sOpenGL = _probing.GetOpenGLVersion();
            if (string.IsNullOrWhiteSpace(sOpenGL))
                sOpenGL = "Undetected";
            lblOpenGL.Text += "  " + sOpenGL;
        }


        private string GetGraphicsCardName()
        {
            SelectQuery queryVideo = new SelectQuery("Win32_VideoController");
            ManagementObjectSearcher searchVideo = new ManagementObjectSearcher(queryVideo);

            StringBuilder sb = new StringBuilder();
            foreach (ManagementObject video in searchVideo.Get())
            {
                sb.Append(string.Format("{0};", video["Name"]));
            }

            return sb.ToString();
        }

    }
}
